﻿using System;
using BD.Standard.YCWH.ProgramParse.Utils;
using Newtonsoft.Json.Linq;
using System.Data;
using BD.Standard.YCWH.ProgramUploadERP.Utils;
using Kingdee.BOS.Authentication;
using Microsoft.SqlServer.Server;
using Kingdee.BOS.JSON;
using Newtonsoft.Json;


namespace BD.Standard.YCWH.ProgramUploadERP
{
    public class Material
    {
        public void PostMaterial(string sql)
        {
            DBConnection Con = new DBConnection();
            DataSet orgIdsSet = Con.getDataSet(sql);
            if (orgIdsSet.Tables[0].Rows.Count == 0) return ;
            foreach (DataRow dataH in orgIdsSet.Tables[0].Rows)
            {
                string reqJson = BuildJson.ERPSaveJson(orgIdsSet,dataH, "0");
                string respJson = WebApi.client.Save("BD_MATERIAL", reqJson);
                int status = JObject.Parse(respJson)["Result"]["ResponseStatus"]["IsSuccess"].ToString().Equals("True") ? 1 : 0;
                Con.getDataSet($"update  YCWH_MATERIAL set status={status},reqJson='{reqJson}',respJson='{respJson}' where ID='{dataH["id"]}'");

            }
        }
    }
}
